Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fallback to other interpreters when specifying a patchlevel. #3475

Merged
merged 1 commit into from
Nov 15, 2021

Conversation

jaharkes
Copy link
Contributor

@jaharkes jaharkes commented Dec 10, 2020

When a project specifies a narrow range for the supported python
versions, i.e. "python ~= 3.6.1" and the current interpreter falls
outside of that range, the fallback code fails to test an available
python3.6 interpreter because of a too strict a test.

Pull Request Check List

Resolves: #3463

  • Added tests for changed code.
  • [N/A] Updated documentation for changed code.

@jaharkes
Copy link
Contributor Author

jaharkes commented Dec 11, 2020

I guess I should elaborate, I hit this when I upgraded my Ubuntu system from 18.04 to 20.04.

The upgrade switched the default python interpreter to 3.8 and the project I was working on had a dependency that was only available for python<3.8. And to add to the fun, another dependency claimed to only support python>=3.6.1.

So I installed python-3.6.12 from the deadsnakes ppa and switched the dependency from python = "^3.6.1" to python = "~3.6.1". But poetry complained it didn't find a compatible version. However when I specify "~3.6" it does find the installed python3.6 binary, but then complains later on that the "current project's Python requirement (>=3.6,<3.7) is not compatible with some of the required packages Python requirements".

Some debugging later, I found that when it is looking for the version of installed python interpreters there is an optimization that skips running interpreters that do not fall in the requested range of supported python versions. And, as is, the test runs if not Version(">=3.6.1,<3.7").allows_all("3.6.*"): which happens to be true because the constraint doesn't allow for version 3.6.0 and so it never bothers to even check if the actual version of the installed python-3.6.12 is acceptable.

@jaharkes jaharkes force-pushed the venv_python_fallback branch from d0bf642 to ed920f6 Compare May 11, 2021 20:00
@jaharkes jaharkes force-pushed the venv_python_fallback branch from ed920f6 to 9e7ae34 Compare June 21, 2021 19:56
@sonarcloud
Copy link

sonarcloud bot commented Jun 21, 2021

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
3.5% 3.5% Duplication

@jaharkes
Copy link
Contributor Author

I'm just rebasing this PR periodically and make sure all the tests still work locally with tox.

Right now I'm locally getting a type error from the python3.7 tests, which is also present in the upstream version without my patch. Also for some reason sonarcloud seems to be complaining about code duplication in test_env.py, but in a part of the file unrelated to the modifications from this patch.

The PR has been waiting for review since December, is there anything I can do to help it make progress?

@finswimmer finswimmer requested a review from a team July 7, 2021 04:24
@jaharkes jaharkes force-pushed the venv_python_fallback branch from 9e7ae34 to 0b43d6d Compare November 10, 2021 14:12
@jaharkes
Copy link
Contributor Author

ping @python-poetry/triage

In my environment, I have multiple python version installed locally, The default python3 interpreter is 3.8.10 but I also have python-3.6.15. The following pyproject.toml is unable to find the 3.6.15 interpreter without this patch.

[tool.poetry]
name = "python_version"
version = "0.1.0"
description = ""
authors = ["test <test@example.org>"]

[tool.poetry.dependencies]
python = ">=3.6.5,<3.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Without patch

$ poetry shell
The currently activated Python version 3.8.10 is not supported by the project (>=3.6.5,<3.7).
Trying to find and use a compatible version. 

  NoCompatiblePythonVersionFound

  Poetry was unable to find a compatible version. If you have one, you can explicitly use it via the "env use" command.

With patch

$ poetry shell
The currently activated Python version 3.8.10 is not supported by the project (>=3.6.5,<3.7).
Trying to find and use a compatible version. 
Using python3.6 (3.6.15)
Creating virtualenv python-version-avkAwIfu-py3.6 in /home/.../.cache/pypoetry/virtualenvs
Spawning shell within /home/.../.cache/pypoetry/virtualenvs/python-version-avkAwIfu-py3.6

@neersighted neersighted self-assigned this Nov 10, 2021
When a project specifies a narrow range for the supported python
versions, i.e. "python ~= 3.6.1" and the current interpreter falls
outside of that range, the fallback code fails to test an available
python3.6 interpreter because of a too strict a test.
@neersighted neersighted merged commit 56f8163 into python-poetry:master Nov 15, 2021
@jaharkes jaharkes deleted the venv_python_fallback branch November 16, 2021 15:07
@finswimmer finswimmer mentioned this pull request Mar 6, 2022
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong python version in new installation
2 participants